var loginSign='';
var urlPage="";
var arr=[];
var timer=0;
var timerP=0;
var nums=0;
window.onload = function() {
	var url = document.location.toString();               
　　  if(url.indexOf("/") != -1){  
        url = url.substring(url.lastIndexOf("/")+1,url.lastIndexOf(".")) ; 
        urlPage=url;
        console.log(url);
　　　}
	slf.getSequenceChild();
    initDate()
};
/*******************************/
var currDT;
var aryDay = new Array("日", "一", "二", "三", "四", "五", "六"); //显示星期
var lastDay; //页面显示的最后一天
var firstDay; //页面显示的第一天
var date = new Date; //获取完整日期
var year = date.getFullYear(); //获取当前年份
//    alert(year);
//上课预约
function recordClass(){
	if(slf.checkSign()){
		//已登录
		slf.getSequenceChild();
		if(slf.schoolId=='a'||slf.schoolId==undefined||slf.schoolId==''){
			var messPrompt="请先完善孩子信息，是否现在去完善？"
			$("#class_model .am-modal-bd").html(messPrompt)
			$("#class_model").modal({
				closeViaDimmer: false,
				onConfirm: function(options) {
					window.location.href = "personal/child_list.html"
		        },
			});
		}else{
		    window.location.href = "class_record.html"
		}
	}else{
		//未登录
		var messPrompt="此功能仅对登录用户开放，是否需要登录？"
		$(".operationModalBody").html(messPrompt)
		$("#operationModal").modal({
			closeViaDimmer: false,
			onConfirm: function(options) {
				window.location.href = "login.html"
	        },
	        onCancel: function() {
	          
	        }
		})
	}
}
//剩余课时
function timeClass(){
	if(slf.checkSign()){
		//已登录
		slf.getSequenceChild();
		if(slf.schoolId=='a'||slf.schoolId==undefined||slf.schoolId==''){
			var messPrompt="请先完善孩子信息，是否现在去完善？"
			$("#class_model .am-modal-bd").html(messPrompt)
			$("#class_model").modal({
				closeViaDimmer: false,
				onConfirm: function(options) {
					window.location.href = "personal/child_list.html"
		        },
			});
		}else{
		    window.location.href = "class_time.html"
		}
	}else{
		//未登录
		var messPrompt="此功能仅对登录用户开放，是否需要登录？"
		$(".operationModalBody").html(messPrompt)
		$("#operationModal").modal({
			closeViaDimmer: false,
			onConfirm: function(options) {
				window.location.href = "login.html"
	        },
	        onCancel: function() {
	          
	        }
		})
	}
}
//进入商城
function seeShopp(){
	window.location.href = "shopp.html"
}
//进入个人中心
function checkPer(){
	if(slf.checkSign()){
		//已登录
		window.location.href = "personal/index.html"
	}else{
		//未登录
		window.location.href = "personal/noLogin.html"
	}
}
//初始化日期加载
function initDate(){
	window.clearInterval(timer);
	window.clearInterval(timerP);
	if(slf.checkSign()){
		console.log("已登录")
		//已登录
		loginSign=1;
	}else{
		console.log("未登录")
		//未登录
		loginSign=0;
	}
    currDT = new Date();
    var dw = currDT.getDay(); //从Date对象返回一周中的某一天(0~6)
    var tdDT; //日期
    //循环加载星期
    var html1="";
    for(var i=dw;i<dw+7;i++){
    	var j=i%7;
    	var str2="周" + "日一二三四五六".charAt(j);
    	html1+="<td onclick='chioceWeek(this)'>"+str2+"</td>"
    }
    $("#mystable tr").append(html1)
    //循环加载日期
    for (var i = 0; i < 7; i++) {
    	var html2="";
    	let Stamp = new Date();
        Stamp.setDate(Stamp.getDate() + i); 
        html2+="<td onclick='chioceData(this)'><div><span>"+Stamp.getDate()+"</span></div></td>"
        $("#mytable tr").append(html2);
        var month=Stamp.getMonth() + 1;
        if(month<10){
        	month='0'+month+""
        }
        var day=Stamp.getDate();
        if(day<10){
        	var day='0'+day+""
        }
        var newtime = '<input type="text" value="' + year + "-" + month + "-" + day + '">';
        $(".newtime").append(newtime);
    }
    $("#mytable tr td:first").addClass("selec")
    var num = $('.selec').index();
    var startDate = $('.newtime').find('input').eq(num).val();
    console.log(startDate)
    if(loginSign==1&&slf.schoolId!=undefined&&slf.schoolId!='a'){
    	//已登录
		var param={
    		date : startDate,
	    };
		getCourList(param)
    }else if(loginSign==0||slf.schoolId==undefined||slf.schoolId=='a'){
    	console.log("未登录")
    	//未登录或信息不完善
		var param={
		   date : startDate,
	    };
		getCourAllList(param)
    }
    //禁止查看今天之前的信息
    var nowTemp = new Date();
    var nowDay = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0).valueOf();
    var nowMoth = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), 1, 0, 0, 0, 0).valueOf();
    var nowYear = new Date(nowTemp.getFullYear(), 0, 1, 0, 0, 0, 0).valueOf();
    var $myStart2 = $('#doc-datepicker');
    var checkin = $myStart2.datepicker({
    	onRender: function(date, viewMode) {
            // 默认 days 视图，与当前日期比较
            var viewDate = nowDay;
            switch (viewMode) {
              // moths 视图，与当前月份比较
              case 1:
                viewDate = nowMoth;
                break;
              // years 视图，与当前年份比较
              case 2:
                viewDate = nowYear;
                break;
            }
            return date.valueOf() < viewDate ? 'am-disabled' : '';
          }
    })
}
/*查询课程包列表（未登录或信息不完善的）*/
function getCourAllList(param){
	$("#course").html("");
	$.ajax({
    	url:"/web/getCourseTheme",
    	type:'get',
    	data:param,
    	beforeSend : function(data){
    		$(".zcc").addClass("am-hide")
	    	$('#my-modal-loading').modal('open');
		},
		success : function(data){
			console.log(data)
			setTimeout(function(){
		    	$('#my-modal-loading').modal('close');
	    	},1000)
			var course =data.obj;
			var html = "";
			if(course==undefined||course==null||course==''||course.length==0){
				html += '<img src="../img/zwsj.png" alt="img" style="width:100%">';				
			}
			if(course.length>0){
				var newList=[];
				for(var i=0;i<course.length;i++){
					var nowTime = (new Date()).getTime();
					var endTime=course[i].endTime;
					endTime = endTime.replace(/-/g,"/");
					var date = new Date(endTime);
					endTime = date.getTime();
					if(nowTime<endTime){
						newList.push(course[i]);
					}  
				}
				for(var i=0;i<course.length;i++){
					var nowTime = (new Date()).getTime();
					var endTime=course[i].endTime;
					endTime = endTime.replace(/-/g,"/");
					var date = new Date(endTime);
					endTime = date.getTime();
					if(nowTime>endTime){
						newList.push(course[i]);
					}  
				}
				console.log(newList)
				for(var i=0;i<newList.length;i++){
					html +='<li class="appointLi">'
						var flag=0;
						html +='<div class="appointDivs am-g" onclick="showInDetail('+newList[i].courseId+','+i+','+flag+','+newList[i].id+',this)">'   
						html +='<div class="curriculumImg am-u-sm-4 pad-0 am-u-md-3" style="height:90px;">' 
						if(newList[i].coverPicture==undefined||newList[i].coverPicture==null||newList[i].coverPicture==''){
							var coverImg=slf.defau.courseIcon(newList[i].courseId)
							html +='<img src="'+coverImg+'" /></div>'
						}else{
							html +='<img src="'+newList[i].coverPicture+'" /></div>'
						}
						html +='<ul class="appointMess am-u-sm-8 pad-0 am-u-md-9" style="height:90px;">'
						html +='<li class="titleLi">'
						html +='<span class="titleDiv" style="font-size:14px;">'+newList[i].name+'</span>'
						if(newList[i].syClassroomNumber==0){
							html +='<span class="rePosition" style="font-size:12px;">已满员</span>'
						}else if(newList[i].syClassroomNumber<7){
							html +='<span class="rePosition" style="font-size:12px;">余位：'+newList[i].syClassroomNumber+'</span>'
						}else{
							html +='<span class="rePosition" style="font-size:12px;color:#26E232">余位：'+newList[i].syClassroomNumber+'</span>'
						}
						html +='</li>'
						html +='<li class="descLi" style="height:20px;">' 
						if(newList[i].briefIntroduction!=undefined){
							html +='<span class="descs" >简介：'+newList[i].briefIntroduction+'</span>'
						}
						html +='</li>'
						html +='<li class="timeLi">'
						html +='<span class="addrs" >地点：'+newList[i].schoolName+'</span>'
						html +='</li>'
						html +='<li class="timeLi">'
						html +='<span class="addrs" >场馆：'+newList[i].classroomName+'</span>'
						html +='</li>'
						html +='<li class="timeLi">'
						html +='<span class="addrs timeClass" >时间：'+newList[i].courseTime+'</span>'
						html +='</li>'
						html +='</ul></div>'
						html +='<div class="classOpen">'
						var nowTime = (new Date()).getTime();
						var startTime=newList[i].courseStartTime;
						startTime = startTime.replace(/-/g,"/");
						var date = new Date(startTime);
						startTime = date.getTime();
						var endTime=newList[i].endTime;
						endTime = endTime.replace(/-/g,"/");
						var date = new Date(endTime);
						endTime = date.getTime();
						if(nowTime<startTime){
							html +='<span class="classTime" style="font-size:12px;">上课时间：'+newList[i].courseTime+'</span>'
						}else{
							//html +='<span class="classTime" style="font-size:12px;">课程预约结束</span>'
						}
						if(newList[i].discountPrice==undefined||newList[i].discountPrice==null||newList[i].discountPrice==''){
					    	var money=newList[i].price
					    }else{
					    	var money=newList[i].discountPrice
					    }
						if(nowTime<startTime){
							if(newList[i].syClassroomNumber>0){
								html +='<span class="classStatus" style="background:#FFAD28" onclick="goBuy('+money+','+newList[i].id+','+newList[i].courseId+','+i+')">立即预约</span>'
							}else{
								html +='<span class="classStatus" style="background:#FFFBF2;float:right;font-size:12px;text-align:right;color:#ff2f2a;">已满员</span>'
							}
						}else if(nowTime>startTime&&nowTime<endTime){
							html +='<span class="classStatus" style="background:#FFFBF2;float:right;font-size:12px;text-align:right;color:#26E232">进行中</span>'
						}else{
							html +='<span class="classStatus" style="background:#FFFBF2;color:#888;float:right;font-size:12px;">课程已结束</span>'
						}
				        html +='</div>'
				        html +='<div class="classBelt" style="background:#fff;height:10px;"></div></li>' 
				}
			}
			$("#course").html(html);
			yomi.yomi();
		}
	});
}
/*查询已登录返回数据*/
function getCourList(param){
	$("#course").html("");
	window.clearInterval(timer);
	window.clearInterval(timerP);
	$.ajax({
    	url:"/web/getCourseThemeLogin",
    	type:'post',
    	data:param,
    	async: false,
    	beforeSend : function(data){
    		$(".zcc").addClass("am-hide")
	    	$('#my-modal-loading').modal('open');
		},
		success : function(data){
			var course = eval('('+ data.obj+')' );
//			console.log(course)
//			console.log("加载登录返回的数据")
			setTimeout(function(){
		    	$('#my-modal-loading').modal('close');
	    	},1000)
			var html = "";
			var flag=1;
			if(course==undefined||course.Pay.length==0&&course.noPay.length==0){
				html += '<img src="../img/zwsj.png" alt="img" style="width:100%">';				
			}else{
				if(course.Pay.length>0){
			        var newListP=[];
					for(var i=0;i<course.Pay.length;i++){
						if(course.Pay[i].downCount>-3600){
							newListP.push(course.Pay[i]);
						}  
					}
					for(var i=0;i<course.Pay.length;i++){
						if(course.Pay[i].downCount<-3600){
							newListP.push(course.Pay[i]);
						}  
					}
					console.log("pay")
					console.log(newListP)
					timerP = setInterval(function () {
			            var newLists = getLastTime(newListP,1);
			        }, 1000)
					for(var i=0;i<newListP.length;i++){
						 html +='<li class="appointLi">'
						html +='<div class="appointDivs am-g" onclick="showInDetail('+newListP[i].courseId+','+i+','+flag+','+newListP[i].id+',this)">'   
						html +='<div class="curriculumImg am-u-sm-4 pad-0 am-u-md-3" style="height:90px;">' 
						if(newListP[i].coverPicture==undefined||newListP[i].coverPicture==null||newListP[i].coverPicture==''){
							var coverImg=slf.defau.courseIcon(newListP[i].coursePageId)
							html +='<img src="'+coverImg+'" /></div>'
						}else{
							html +='<img src="'+newListP[i].coverPicture+'" /></div>'
						}
						html +='<ul class="appointMess am-u-sm-8 pad-0 am-u-md-9" style="height:90px;">'
						html +='<li class="titleLi">'
						html +='<span class="titleDiv" style="font-size:14px;">'+newListP[i].name+'</span>'
						if(newListP[i].syClassroomNumber==0){
							html +='<span class="rePosition" style="font-size:12px;">已满员</span>'
						}else if(newListP[i].syClassroomNumber<7){
							html +='<span class="rePosition" style="font-size:12px;">余位：'+newListP[i].syClassroomNumber+'</span>'
						}else{
							html +='<span class="rePosition" style="font-size:12px;color:#26E232">余位：'+newListP[i].syClassroomNumber+'</span>'
						}
						html +='</li>'
						html +='<li class="descLi" style="height:20px;">' 
						if(newListP[i].briefIntroduction!=undefined){
							html +='<span class="descs" >简介：'+newListP[i].briefIntroduction+'</span>'
						}
						html +='</li>'
						html +='<li class="timeLi">'
						html +='<span class="addrs" >地点：'+newListP[i].schoolName+'</span>'
						html +='</li>'
						html +='<li class="timeLi">'
						html +='<span class="addrs" >场馆：'+newListP[i].classroomName+'</span>'
						html +='</li>'
						html +='<li class="timeLi">'
						html +='<span class="addrs timeClass" >时间：'+newListP[i].courseTime+'</span>'
						html +='</li>'
						html +='</ul></div>'
						html +='<div class="classOpen">'
						if(newListP[i].discountPrice==undefined||newListP[i].discountPrice==null||newListP[i].discountPrice==''){
					    	var money=newListP[i].price
					    }else{
					    	var money=newListP[i].discountPrice
					    }
						if(newListP[i].downCount<-3600){
							html +='<span class="classTime" style="font-size:12px;"></span>'
							html +='<span class="classStatus" style="float:right;color:#888;font-size:12px;background:#FFFBF2;text-align:right">课程已结束</span>'
						}else if(newListP[i].downCount<0&&newListP[i].downCount>-3600){
							html +='<span class="classTime" style="font-size:12px;"></span>'
							html +='<span class="classStatus" style="float:right;color:#26E232;font-size:12px;background:#FFFBF2;text-align:right">进行中</span>'
						}else if(newListP[i].downCount<10800){
							html +='<span class="classTime" style="font-size:12px;"></span>'
							html +='<span class="classStatus co-26" style="float:right;font-size:12px;background:#FFFBF2;text-align:right">课程即将开始</span>'
						}else{
							html +='<span class="classTime" style="font-size:12px;">距离开课：<span class="coutDownTime" id="timer'+i+'"></span></span>'
							if(newListP[i].syClassroomNumber>0){
								html +='<span class="classStatus btn'+i+'" ids='+newListP[i].id+'  onclick="cancle('+money+','+newListP[i].id+','+newListP[i].courseId+','+i+')">取消预约</span>'
							}else{
								html +='<span class="classStatus" style="background:#FFFBF2;float:right;font-size:12px;text-align:right;color:#ff2f2a;">已满员</span>'
							}
						}
				        html +='</div>'
				        html +='<div class="classBelt" style="background:#fff;height:10px;"></div></li>'
					}
				}
				if(course.noPay.length>0){
			        var newList=[];
					for(var i=0;i<course.noPay.length;i++){
						if(course.noPay[i].downCount>-3600){
							newList.push(course.noPay[i]);
						}  
					}
					for(var i=0;i<course.noPay.length;i++){
						if(course.noPay[i].downCount<-3600){
							newList.push(course.noPay[i]);
						}  
					}
					console.log("nopay")
					console.log(newList)
					timer = setInterval(function () {
			            var newLists = getLastTime(newList,2);
			        }, 1000)
					for(var i = 0; i < newList.length ; i++){
						html +='<li class="appointLi">'
						html +='<div class="appointDivs am-g" onclick="showInDetail('+newList[i].courseId+','+i+','+flag+','+newList[i].id+',this)">'   
						html +='<div class="curriculumImg am-u-sm-4 pad-0 am-u-md-3" style="height:90px;">' 
						if(newList[i].coverPicture==undefined||newList[i].coverPicture==null||newList[i].coverPicture==''){
							var coverImg=slf.defau.courseIcon(newList[i].coursePageId)
							html +='<img src="'+coverImg+'" /></div>'
						}else{
							html +='<img src="'+newList[i].coverPicture+'" /></div>'
						}
						html +='<ul class="appointMess am-u-sm-8 pad-0 am-u-md-9" style="height:90px;">'
						html +='<li class="titleLi">'
						html +='<span class="titleDiv" style="font-size:14px;">'+newList[i].name+'</span>'
						if(newList[i].syClassroomNumber==0){
							html +='<span class="rePosition" style="font-size:12px;">已满员</span>'
						}else if(newList[i].syClassroomNumber<7){
							html +='<span class="rePosition" style="font-size:12px;">余位：'+newList[i].syClassroomNumber+'</span>'
						}else{
							html +='<span class="rePosition" style="font-size:12px;color:#26E232">余位：'+newList[i].syClassroomNumber+'</span>'
						}
						html +='</li>'
						html +='<li class="descLi" style="height:20px;">' 
						if(newList[i].briefIntroduction!=undefined){
							html +='<span class="descs" >简介：'+newList[i].briefIntroduction+'</span>'
						}
						html +='</li>'
						html +='<li class="timeLi">'
						html +='<span class="addrs" >地点：'+newList[i].schoolName+'</span>'
						html +='</li>'
						html +='<li class="timeLi">'
						html +='<span class="addrs" >场馆：'+newList[i].classroomName+'</span>'
						html +='</li>'
						html +='<li class="timeLi">'
						html +='<span class="addrs timeClass">时间：'+newList[i].courseTime+'</span>'
						html +='</li>'
						html +='</ul></div>'
						html +='<div class="classOpen">'
						if(newList[i].downCount<0){
							//html +='<span class="classTime" style="font-size:12px;">课程预约结束</span>'
						}else if(newList[i].downCount<10800){
							//html +='<span class="classTime" style="font-size:12px;">课程即将开始</span>'
						}else{
							html +='<span class="classTime" style="font-size:12px;">距离开课：<span class="coutDownTime" id="timers'+i+'"></span></span>'
						}
						if(newList[i].discountPrice==undefined||newList[i].discountPrice==null||newList[i].discountPrice==''){
					    	var money=newList[i].price
					    }else{
					    	var money=newList[i].discountPrice
					    }
						if(newList[i].downCount<-3600){
							html +='<span class="classStatus" style="background:#FFFBF2;float:right;color:#888;font-size:12px;text-align:right">课程已结束</span>'
						}else if(newList[i].downCount<0&&newList[i].downCount>-3600){
							html +='<span class="classStatus" style="background:#FFFBF2;float:right;color:#26E232;font-size:12px;text-align:right">进行中</span>'
						}else if(newList[i].downCount<10800){
							html +='<span class="classStatus" style="background:#FFFBF2;float:right;font-size:12px;color:#26E232;text-align:right">课程即将开始</span>'
						}else{
							if(newList[i].syClassroomNumber>0){
								html +='<span class="classStatus btn'+i+'" style="background:#FFAD28" onclick="goBuy('+money+','+newList[i].id+','+newList[i].courseId+','+i+')">立即预约</span>'
							}else{
								html +='<span class="classStatus" style="background:#FFFBF2;float:right;font-size:12px;text-align:right;color:#ff2f2a;">已满员</span>'
							}
						}
				        html +='</div>'
				        html +='<div class="classBelt" style="background:#fff;height:10px;"></div></li>'      
					}
				}
			}
			
			$("#course").html(html);
			yomi.yomi();
		}
	});
}
/*获取倒计时*/
function getLastTime(data,num){
	if(data!=undefined&&data.length>0){
		for (var i = 0; i < data.length; i++) {
		      var intDiff = data[i].downCount;//获取数据中的时间戳  
		      var day = 0, hour = 0, minute = 0, second = 0;
		      if (intDiff > 0) {//转换时间  
		        day = Math.floor(intDiff / (60 * 60 * 24));
		        hour = Math.floor(intDiff / (60 * 60)) - (day * 24);
		        minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60);
		        second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
		        if (day <= 9) day = '0' + day;
		        if (hour <= 9) hour = '0' + hour;
		        if (minute <= 9) minute = '0' + minute;
		        if (second <= 9) second = '0' + second;
		        data[i].downCount--;
		        var str = day+'天'+hour + '小时' + minute + '分钟' + second+'秒';
		        if(num==1){
		        	//Pay的倒计时
		        	$("#timer"+i+"").html(str)
		        }else if(num==2){
		        	//noPay的倒计时
		        	$("#timers"+i+"").html(str)
		        }
		      }else{
		    	 
		      } 
		 }
	}
}
/*跳转课程详情*/
function showInDetail(courseId,num,flag,id,obj){//小包Id
	if(flag==0){
		//未登录
		window.location.href='basepkg_details.html?courseId='+courseId+'&flag=0&id='+id+''
	}else if(flag==1){
		var title=$(obj).parent(".appointLi").find(".classTime").html();
		if(title=="课程已开始"||title=="课程预约结束"){
			//登录无倒计时
			window.location.href='basepkg_details.html?courseId='+courseId+'&flag=1&id='+id+''
		}else{
			//登录有倒计时
			if($("#timer"+num+"").html()==undefined){
				var nowTime=$("#timers"+num+"").html();
			}else{
				var nowTime=$("#timer"+num+"").html();
			}
			console.log(nowTime)
			//已登录
			window.location.href='basepkg_details.html?courseId='+courseId+'&nowTime='+encodeURI(encodeURI(nowTime))+'&flag=1&id='+id+''
		}
		
	}
}
//取消预约
function cancle(money,id,course_id,num){
	$(".zcc").removeClass("am-hide")
	setTimeout(function(){
		nums++;
		if(nums==1){
			var nowTime=$("#timer"+num+"").html();
			console.log(nowTime)
			slf.ajax({
		        url: "/getCancelMoney",//获取退还立方币
		        param : {
		        	id:id,
		        	seconds:nowTime,
		        },
		        success: function (data) {
		        	$(".zcc").addClass("am-hide")
		        	console.log("获取退还立方币")
		        	console.log(data)
		        	if(data.res==1){
		        		var returnMoney=data.obj;
		        		$('#cancleModal .am-modal-bd').html("");
		        		$('#cancleModal .am-modal-bd').html("如若取消本次预约，预计退还您<span style='color:red'>"+returnMoney+"</span>立方币，是否确定取消本课程？");
		        		var $confirm = $('#cancleModal');
		                var confirm = $confirm.data('amui.modal');
		                var onConfirm = function() {
		                	window.clearInterval(timer);
		                	window.clearInterval(timerP);
		                	slf.ajax({
		    			        url: "/cancelCourseTheme",
		    			        param : {
		    			        	courseId : course_id,
		    			        	id:id,
		    			        	seconds:nowTime,
		    			        },
		    			        success: function (data) {
		    			        	console.log(data)
		    			        	console.log("取消预约返回值")
		    			           if(data.res==1){
		    			        	    console.log("取消预约成功");
		    			        	    $(".alert1").html("取消预约成功，已成功给您返回"+data.obj+"立方币！")
		    			        	    $("#alert1").modal('open');
				        				var num = $('.selec').index();
		    				        	var startDate = $('.newtime').find('input').eq(num).val();
		    				        	console.log("日期")
		    				        	console.log(startDate)
		    				        	var param={
		    				        		date:startDate
		    				        	}
		    				        	$("#course").html("");
		    			        	    window.clearInterval(timer);
		    			        	    window.clearInterval(timerP);
		    			        	    getCourList(param)
		    			           }
		    			        }
		    			    });
		                };
		                var onCancel = function() {
		                    
		                }
		                if (confirm) {
		                  confirm.options.onConfirm =  onConfirm;
		                  confirm.options.onCancel =  onCancel;
		                  confirm.toggle(this);
		                } else {
		                  $confirm.modal({
		                    relatedElement: this,
		                    closeViaDimmer: false,
		                    onConfirm: onConfirm,
		                    onCancel: onCancel
		                  });
		                }
		                nums=0;
		        	}
		        	
		        }
		    });
		}
	},1)
	
}
//取得当前日期一周内的某一天
function getWeek(i) {
    var now = new Date();
    var n = now.getDay();
    var start = new Date();
    start.setDate(now.getDate() - n + i); //取得一周内的第一天、第二天、第三天...
    return start;
}
function getWeekss(i) {
    var now = new Date($("#doc-datepicker").val().replace(/-/g,   "/"));
    var n = now.getDay();
    var start = new Date();
    start.setDate(now.getDate() - n + i); //取得一周内的第一天、第二天、第三天...
    return start;
}

//取得当前日期一周内的七天
function getDays() {
    var days = new Array();
    for (var i = 1; i <= 7; i++) {
        days[i - 1] = getWeek(i);
    }
    return days;
}
function getDayss() {
    var days = new Array();
    for (var i = 1; i <= 7; i++) {
        days[i - 1] = getWeekss(i);
    }
    return days;
}

/**********************************************************************/
//点击选择日期
function chioceData(obj){
	$(".zcc").removeClass("am-hide")
	window.clearInterval(timer);
	window.clearInterval(timerP);
	setTimeout(function(){
		var num = $(obj).index();
		$("#course").html("");
		if(num < 7){
			$("#mytable tr td").removeAttr("class");
		    $(obj).attr("class", "selec");
		    var num = $(obj).index();
		    $(".datetime").find("input").val($(".newtime").find("input").eq(num).val());
		    var startDate = $('.newtime').find('input').eq(num).val();
		    if(loginSign==1&&slf.schoolId!=undefined&&slf.schoolId!='a'){
		    	//已登录
	    		var param={
	    	    		date : startDate,
	    		    };
	    			getCourList(param)
		    }else if(loginSign==0||slf.schoolId==undefined||slf.schoolId==null||slf.schoolId=='a'){
		    	//未登录或信息不完善
				var param={
		    		date : startDate,
			    };
				getCourAllList(param)
		    }
		}
	},1)
}
//点击星期时间
function chioceWeek(obj){
	window.clearInterval(timer);
	window.clearInterval(timerP);
	$("#course").html("");
	setTimeout(function(){
		var num = $(obj).index();
		if(num < 7){
			$("#mytable tr td").removeAttr("class");
			$("#mytable tr").find("td").eq(num).attr("class","selec");
			$(".datetime").find("input").val($(".newtime").find("input").eq(num).val());
		    var startDate = $('.newtime').find('input').eq(num).val();
		    if(loginSign==1&&slf.schoolId!=undefined&&slf.schoolId!='a'){
		    	//已登录
		    	var param={
		    		date : startDate,
			    };
				getCourList(param)
		    }else if(loginSign==0||slf.schoolId==undefined||slf.schoolId==null||slf.schoolId=='a'){
		    	//未登录或信息不完善
		    	var param={
		    		date : startDate,
			    };
				getCourAllList(param)
		    }
		}
	},1);
	
}

//模态框确认按钮
$('.default').on('change',function(){
	window.clearInterval(timer);
	window.clearInterval(timerP);
	$("#course").html("");
	setTimeout(function(){
		var startDate = $("#doc-datepicker").val();
		var today=new Date(startDate.replace(/-/g,"/"));
		var year = today.getFullYear(); //获取当前年份
		var dw = today.getDay(); //从Date对象返回一周中的某一天(0~6) 显示的是当前日期位置 
		var dataTime=today.getDate();
		$("#mystable tr").html("");
		$("#mytable tr").html("")
	    //循环加载星期
	    var html1="";
	    for(var i=dw;i<dw+7;i++){
	    	var j=i%7;
	    	var str2="周" + "日一二三四五六".charAt(j);
	    	html1+="<td onclick='chioceWeek(this)'>"+str2+"</td>"
	    }
	    $("#mystable tr").append(html1)
	    //循环加载日期
	    for (var i = 0; i < 7; i++) {
	    	var html2="";
	    	let Stamp = new Date(startDate.replace(/-/g,"/"));
	    	Stamp.setDate(Stamp.getDate() + i); 
	        html2+="<td onclick='chioceData(this)'><div><span>"+Stamp.getDate()+"</span></div></td>"
	        $("#mytable tr").append(html2);
	        var newtime = '<input type="text" value="' + year + "-" + (Stamp.getMonth() + 1) + "-" + Stamp.getDate() + '">';
	        $(".newtime").append(newtime);
	    }
	    $("#mytable tr td:first").addClass("selec")
	    var startDate = $("#doc-datepicker").val();
		if(startDate != ''){
			if(loginSign==1&&slf.schoolId!=undefined&&slf.schoolId!='a'){
		    	//已登录
				var param={
		    		date : startDate,
			    };
				getCourList(param)
			 }else if(loginSign==0||slf.schoolId==undefined||slf.schoolId=='a'){
		    	//未登录或信息不完善
				 var param={
		    		date : startDate,
			    };
				getCourAllList(param)
		    }
		}
	},1);
	
})
//购买
function goBuy(money,id,courseId,num){
	if(id==undefined||id==""||id==null){
		return false
	}else{
		$(".zcc").removeClass("am-hide")
		nums++;
		console.log("购买")
		setTimeout(function(){
			if(nums==1){
				if(slf.checkSign()){
					var childMess=slf.getSequenceChild();
					if(slf.schoolId=='a'||slf.schoolId==undefined||slf.schoolId==null){
						$(".zcc").addClass("am-hide")
						var messPrompt="请先完善孩子信息，是否现在去完善？"
						$("#class_model .am-modal-bd").html(messPrompt)
						$("#class_model").modal({
							closeViaDimmer: false,
							onConfirm: function(options) {
								window.location.href = "personal/child_list.html"
					        },
						});
						nums=0;
					}else{
						console.log(childMess)
						console.log("获取返回孩子信息")
						if(childMess.state==0){//无期望上课时间
							console.log("无孩子期望上课时间")
							$(".zcc").addClass("am-hide")
							$("#class_model .am-modal-bd").html("您还未选择孩子期望上课时间段，是否现在去完善？")
							$("#class_model").modal({
								relatedTarget: this,
								closeViaDimmer: false,
								onConfirm: function(options) {
									window.location.href = "personal/add_child.html?userId="+childMess.userId+"&childrenId="+childMess.childrenId+""; //去其网上可时间  
								}
							})
							nums=0;
						}else if(childMess.state==1){//you期望上课时间
							console.log("有孩子期望上课时间");
							if($("#timer"+num+"").html()==undefined){
								var nowTime=$("#timers"+num+"").html();
							}else{
								var nowTime=$("#timer"+num+"").html();
							}
							//判断孩子时间是否被占用以及课程是否已被购买
							slf.ajax({
						        url: "/beOccupiedCourse",
						        param : {
						        	id:id,
						        	seconds:nowTime,
						        	courseId:courseId,
						        },
						        success: function (data) {
						        	console.log(data)
						        	console.log("获取是否被占用返回值或者vip或者3小时")
						        	if(data.res==1){
						        		//无占用
										$('#class_model .am-modal-bd').html("是否花费<span class='text-FF2A2A'>"+money+"</span>个立方币预约本课程?");
										var $confirm = $('#class_model');
								        var confirm = $confirm.data('amui.modal');
								        $(".zcc").addClass("am-hide")
								        var onConfirm = function() {
											slf.ajax({
												url:'/getCourseThemePay',
												param:{
													id:id,
													courseId:courseId,
												},
												success:function(data){
													console.log(data)
													console.log("判断是否购买")
													if(data.obj==0){
														//钱不够
														$("#buyMoneyModal").modal({
															relatedTarget: this,
															closeViaDimmer: false,
													        onConfirm: function(options) {
													        	window.location.href = "recharge.html"; //去充值页面
													        },
														});
														nums=0;
													}else if(data.obj==1){
														//成功
														$("#alert_model .am-modal-bd").html("购买成功！");
														$('#alert_model').modal('open');
														setTimeout(function(){
														  $('#alert_model').modal('close');
														},2000);
														nums=0;
														var num = $('.selec').index();
											        	var startDate = $('.newtime').find('input').eq(num).val();
											        	console.log("日期")
											        	console.log(startDate)
											        	var param={
											        		date:startDate
											        	}
											        	$("#course").html("");
						    			        	    window.clearInterval(timer);
						    			        	    window.clearInterval(timerP);
						    			        	    getCourList(param)
													}
												}
											});
								        };
								        var onCancel = function() {
								            
								        }
								        if (confirm) {
								          confirm.options.onConfirm =  onConfirm;
								          confirm.options.onCancel =  onCancel;
								          confirm.toggle(this);
								        } else {
								          $confirm.modal({
								            relatedElement: this,
								            closeViaDimmer: false,
								            onConfirm: onConfirm,
								            onCancel: onCancel
								          });
								        }
						        	}else{
						        		//3小时和vip和占用
						        		nums=0;
						        		$("#class_model .am-modal-bd").html(data.resMsg);
						        		$(".zcc").addClass("am-hide");
						        		$("#class_model").modal({
						        			closeViaDimmer: false,
						        		});
				        				var num = $('.selec').index();
							        	var startDate = $('.newtime').find('input').eq(num).val();
							        	console.log("日期")
							        	console.log(startDate)
							        	var param={
							        		date:startDate
							        	}
							        	$("#course").html("");
		    			        	    window.clearInterval(timer);
		    			        	    window.clearInterval(timerP);
		    			        	    getCourList(param)
						        	}
						        	nums=0;
						        }
						    });
						}
					}
				}else{
					nums=0;
					$(".zcc").addClass("am-hide")
					var messPrompt="此功能仅对登录用户开放，是否需要登录？"
					$(".operationModalBody").html(messPrompt)
					$("#operationModal").modal({
						closeViaDimmer: false,
						onConfirm: function(options) {
							window.location.href = "login.html"
				        },
				        onCancel: function() {
				          
				        }
					})
				}
			}
		},1)
	}
}